<!DOCTYPE html>
<html>
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui"/>
	<meta name="apple-mobile-web-app-capable" content="yes"/>
	<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
	<meta name="format-detection" content="telephone=no, email=no"/>
	<meta charset="UTF-8">
	<title>收货地址</title>
	<link rel="stylesheet" href="themes/css/core.css">
	<link rel="stylesheet" href="themes/css/icon.css">
	<link rel="stylesheet" href="themes/css/home.css">
	<link rel="icon" type="image/x-icon" href="favicon.ico">
	<link href="iTunesArtwork@2x.png" sizes="114x114" rel="apple-touch-icon-precomposed">

</head>
<body style="background:#eee">
<div id="el">
	<header class="aui-header-default aui-header-fixed ">
		<a href="javascript:history.back(-1)" class="aui-header-item">
			<i class="aui-icon aui-icon-back"></i>
		</a>
		<div class="aui-header-center aui-header-center-clear">
			<div class="aui-header-center-logo">
				<div class="">收货地址</div>
			</div>
		</div>
		<a href="#" class="aui-header-item-icon"   style="min-width:0">
			<i class="aui-icon"></i>
		</a>
	</header>

	<section class="aui-myOrder-content">
		<div class="aui-Address-box" v-for="all in allAddress">
			<div class="aui-Address-box-item">
				<div class="aui-Address-box-item-bd">
					<p v-text="all.name"></p>
				</div>
				<div class="aui-Address-box-item-ft">
					<p v-text="all.tel"></p>
				</div>
			</div>
			<div class="aui-Address-box-item">
				<div class="aui-Address-box-item-bd">
					<p v-text="all.addr"></p>
				</div>
			</div>
			<div class="aui-Address-box-item">
				<div class="aui-Address-box-item-bd">
					<p>
						<input :value="all.userAddressId" type="hidden"/>
						<input type="checkbox" class="check goods-check goodsCheck" v-if="all.isdefault==1" checked="checked" style="background-size: 17px 17px;">
						<input type="checkbox" class="check goods-check goodsCheck" v-else style="background-size: 17px 17px;">
						<em style="padding-left:24px;">默认地址</em>
					</p>
				</div>
				<div class="aui-Address-box-item-ft">
					<p @click="delete1(all.userAddressId)">删除</p>
				</div>
			</div>
		</div>

		<div class="aui-out">
			<a href="my-edit-address.html">新建收货地址</a>
		</div>
	</section>
</div>

	<script type="text/javascript" src="themes/js/jquery.min.js"></script>
	<script type="text/javascript" src="themes/js/aui.js"></script>
	<script src="themes/js/vue.js"></script>
	<script type="text/javascript" >
		var vue = new Vue({
			el:"#el",
			data:{
				allAddress:[],
			},
			created:function(){
				this.init();
			},
			methods:{
				init:function(){
					var _this = this;
					//默认地址查询
					$.ajax({
						type:"get",
						url:"/weixin/queryUserAddress",
						dataType:"json",
						success:function(da){
							_this.allAddress = da.li;
							// alert(_this.allAddress[0].name);
						}
					});
				},
				delete1:function (userAddressId) {
					var f = confirm("确认删除？");
					if(f){
						$.ajax({
							type:"get",
							url:"/ShoppingMallOrder/deleteUserAddress",
							data:{"userAddressId":userAddressId},
							dataType:"json",
							success:function(da){
								location.href="my-addres.html";
							}
						});
					}

				}

			},
		});
		$("body").on("click",".goodsCheck",function(){
			var che = $(".goodsCheck");
			for (var i = 0;i < che.length;i++){
				if($(this) != $(che[i])){
					$(che[i]).prop("checked","");
				}
			}
			$(this).prop("checked","checked");
			var userAddressId  = $(this).parent().children().eq(0).val();
			//将所有的默认修改为0
			$.ajax({
				type:"get",
				url:"/ShoppingMallOrder/updateUserAddressAllDefaultToZero",
				dataType:"json",
				success:function(da){
					//修改选中的默认修改为1
					$.ajax({
						type:"get",
						url:"/ShoppingMallOrder/updateUserAddressDefaultToOne",
						data:{"userAddressId":userAddressId},
						dataType:"json",
						success:function(da){
							location.href="order.html";
						}
					});
				}
			});

		});


        /**
         * Javascript API调用Tab
         */
        !function ($) {
            var $tab = $('#J_Tab');

            $tab.tab({
                nav: '.tab-nav-item',
                panel: '.tab-panel-item',
                activeClass: 'tab-active'
            });

			/*
			 $tab.find('.tab-nav-item').on('open.ydui.tab', function (e) {
			 console.log('索引：%s - [%s]正在打开', e.index, $(this).text());
			 });
			 */

            $tab.find('.tab-nav-item').on('opened.ydui.tab', function (e) {
                console.log('索引：%s - [%s]已经打开了', e.index, $(this).text());
            });
        }(jQuery);
	</script>

</body>
</html>